<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="root"></div>
  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <script src="../js/babel.min.js"></script>
  <script type="text/babel">
    class MyComponent extends React.Component {
      // 写成箭头函数的好处是，不需要再为函数 this 绑定当前组件实例
      onBtnClick = (e) => {
        console.log(this)
        // 第二步：直接使用 this.refs 就可以获取字符串 ref
        console.log(this.refs.inputRef)
      }
      render() {
        return (
          <div>
            { /* 第一步：添加 ref，值为一个字符串 */ }
            <input ref="inputRef" placeholder="点击右侧按钮获取我的值" />
            <button onClick={this.onBtnClick}>点击获取值</button>
          </div>
        )
      }
    }
    ReactDOM.render(<MyComponent />, document.getElementById('root'))
  </script>
</body>
</html>